package com.sp.scmdb.utils;

import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class DateTimeSpan {

	private DateTime inTime;
	private DateTime outTime;

	public DateTimeSpan(DateTime inTime, DateTime outTime) {
		this.inTime = inTime;
		this.outTime = outTime;
	}

	public boolean isTrueDateTime(String startTime, String endTime) {
		if (!inTime.isBefore(getDateTime(startTime)) && !getDateTime(endTime).isBefore(inTime)) {
			return true;
		}
		return false;
	}

	public boolean isTrueDateTimeOfMonth(DateTime startTime, DateTime endTime) {
		if (!inTime.isBefore(startTime) && !endTime.isBefore(inTime)) {
			return true;
		}
		return false;
	}

	public Integer getMinute(DateTime inTime, DateTime outTime) {
		Duration duration = new Duration(inTime, outTime);
		return Integer.parseInt(String.valueOf(duration.getMillis() / 1000 / 60));
	}

	public DateTime getDateTime(String dateTimeStr) {
		DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
		return formatter.parseDateTime(dateTimeStr);
	}

	public DateTime getInTime() {
		return inTime;
	}

	public void setInTime(DateTime inTime) {
		this.inTime = inTime;
	}

	public DateTime getOutTime() {
		return outTime;
	}

	public void setOutTime(DateTime outTime) {
		this.outTime = outTime;
	}
}
